local skel = fk.CreateSkill{
  name = "#affluence_skill_delay",
}
Fk:loadTranslationTable{
  ["#affluence_skill_delay"] = "富贵",
  [":#affluence_skill_delay"] = "富贵",
}
local isAlly = function (player, target)
  if player == target then
    return false
  end
  local role1, role2 = player.role, target.role
  local dict = { "lord", "loyalist" }
  return role1 == role2 or (table.contains(dict, role1) and table.contains(dict, role2))
end
---@type TrigSkelSpec<MoveCardsFunc>
local affluence_skill_delay = {
  can_refresh = function (self, event, target, player, data)
    if table.find(player.room.alive_players, function (p)
      return p:getMark("@@affluence_skill") == 1
    end) then
      local allys, n = {}, 0
      for _, move in ipairs(data) do
        if move.toArea == Card.PlayerHand and move.to and player == move.to then
          allys = table.filter(player.room.alive_players, function (p)
            return isAlly(move.to, p) and p:getMark("@@affluence_skill") == 1
          end)
          if #allys > 0 then
            for _, info in ipairs(move.moveInfo) do
              n = n + 1
            end
            if n > 0 then
              event:setCostData(self, { num = n, allys = allys })
              return true
            end
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    local num, allys = dat.num, dat.allys
    for _, p in ipairs(allys) do
      if not p.dead then
        room:setPlayerMark(p, "@@affluence_skill", 0)
        p:drawCards(num, skel.name)
      end
    end
  end
}
skel:addEffect(fk.AfterCardsMove, affluence_skill_delay)
return skel